package org.kermeta.spem.activityautomation.eclipse.createkermetacheckerproject;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.kermeta.spem.activityautomation.eclipse.createkermetacheckerproject.wizards.KermetaProjectNewWizard;

public class CreateKermetaCheckerProject implements IObjectActionDelegate {
	
	private IStructuredSelection selection;

	@Override
	public void run(IAction action) {
		// TODO Auto-generated method stub

	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		this.selection =
				selection instanceof IStructuredSelection
				? (IStructuredSelection) selection
						: null;

	}

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// TODO Auto-generated method stub

	}

	public void run(IWorkbenchWindow window, String contextModelPath){
		//Create a new Kermeta project
		try{
			KermetaProjectNewWizard kermetaProjectNewWizard = new KermetaProjectNewWizard(contextModelPath);
			kermetaProjectNewWizard.init(window.getWorkbench(), selection);
			WizardDialog dialog = new WizardDialog(window.getShell(), kermetaProjectNewWizard);
			dialog.open();
		}catch(Exception e){
			e.printStackTrace();
		}
		//Generate visitor code
//		ResourceSet rSet = new ResourceSetImpl();
//		rSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
//		MainRunner.init4eclipse();
//		rSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
//		MainRunner.init();
//		rSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
//		MainClass m = KerRichFactory.createMainClass();
//		m.mainOperation(contextModelPath);
	}
}
